package com.arui.yygh.msm.utils;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MsmUtils {
    public static boolean sendMsm(String code,String phone){
        //生产环境请求地址：app.cloopen.com
        String serverIp = "app.cloopen.com";
        //请求端口
        String serverPort = "8883";
        //主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
        String accountSId = "8aaf070879f030fc017a2e203fab128c";
        String accountToken = "2d1bb201bd45406b8effab25339e1c37";
        //请使用管理控制台中已创建应用的APPID
        String appId = "8aaf070879f030fc017a2e2040a51292";
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init(serverIp, serverPort);
        sdk.setAccount(accountSId, accountToken);
        sdk.setAppId(appId);
        sdk.setBodyType(BodyType.Type_JSON);
        //发送短信至手机号
        String to = phone;
        //短信模板
        String templateId= "1";
        //这里模拟一下验证码123456，10分钟内到期
        String[] datas = {code,"2"};
        HashMap<String, Object> result = sdk.sendTemplateSMS(to,templateId,datas);
        if("000000".equals(result.get("statusCode"))){
            //正常返回输出data包体信息（map）
//            HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
//            Set<String> keySet = data.keySet();
//            for(String key:keySet){
//                Object object = data.get(key);
//                System.out.println(key +" = "+object);
//            }
            return true;
        }else{
            //异常返回输出错误码和错误信息
            return false;
        }
    }
    public static boolean sendMsm(String phone, Map<String,Object> param){
        //生产环境请求地址：app.cloopen.com
        String serverIp = "app.cloopen.com";
        //请求端口
        String serverPort = "8883";
        //主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
        String accountSId = "8aaf070879f030fc017a2e203fab128c";
        String accountToken = "2d1bb201bd45406b8effab25339e1c37";
        //请使用管理控制台中已创建应用的APPID
        String appId = "8aaf070879f030fc017a2e2040a51292";
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init(serverIp, serverPort);
        sdk.setAccount(accountSId, accountToken);
        sdk.setAppId(appId);
        sdk.setBodyType(BodyType.Type_JSON);
        //发送短信至手机号
        String to = "13425091819";
        //短信模板
        String templateId= "1";
        //这里模拟一下验证码123456，10分钟内到期
        String[] datas = {"123456","2"};
        HashMap<String, Object> result = sdk.sendTemplateSMS(to,templateId,datas);
        if("000000".equals(result.get("statusCode"))){
            //正常返回输出data包体信息（map）
//            HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
//            Set<String> keySet = data.keySet();
//            for(String key:keySet){
//                Object object = data.get(key);
//                System.out.println(key +" = "+object);
//            }
            return true;
        }else{
            //异常返回输出错误码和错误信息
            return false;
        }
    }

}
